package com.ellwood.copyright.framework.config.other;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * @ProjectName: ell-copyright-pro
 * @PackageName: com.ellwood.copyright.framework.config.other
 * @ClassName: CorsFilter
 * @Description: // 跨域配置
 * @Author: Ellwood
 * @CreateDate: 2024/11/21 - 15:08
 * @Version: V1.0.0
 */
@Configuration
public class MyCorsFilter {

    @Bean
    public CorsFilter EllCorsFilter(){
        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        final CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedOriginPattern("*");
        corsConfiguration.addAllowedMethod("*");
        source.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsFilter(source);
    }

}
